<template>
  <div>
    <UploadExcel :on-success="handleSuccess">
    </UploadExcel>
  </div>
</template>

<script>
import UploadExcel from '@/components/UploadExcel/index.vue'
import { importEmployee } from '@/api/Employees'
export default {
  name: '',
  components: { UploadExcel },
  props: {
  },
  data() {
    return {

    }
  },
  created() {},
  mounted() {},
  methods: {
    async handleSuccess(results) { // 通过父传子接收数据
      console.log(data)
      const userRelations = {
        '入职日期': 'timeOfEntry',
        '手机号': 'mobile',
        '姓名': 'username',
        '转正日期': 'correctionTime',
        '工号': 'workNumber'
      }
      const data = results.map(t => { // 数据转换
        const item = {}
        for (const k in t) {
          item[userRelations[k]] = t[k]
          console.log('t[k]', t[k])
          console.log('userRelations[k]', userRelations[k])
        }
        return item
      })

      await importEmployee(data)// 发请求做上传
      console.log(data)
      this.$message.success('导入成功')
    }

  }
}
</script>

<style lang="scss" scoped>

</style>
